import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:ytbusiness/config/yt_theme.dart';
import 'package:ytbusiness/utils/helper.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';

//我的订单
class MyOrder extends StatefulWidget {
  final List<String> numList;
  final List<String> titleList;

  const MyOrder({Key key, this.numList, this.titleList}) : super(key: key);

  @override
  _MyOrderState createState() => _MyOrderState();
}

class _MyOrderState extends State<MyOrder> {

  bool isShow = false;//默认隐藏

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.only(
          top: setWidth(15), left: setWidth(15), right: setWidth(15),bottom: setWidth(15)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Container(
                child: Text(
                  "我的订单",
                  style: TextStyle(
                      color: YTTheme.theme,
                      fontSize: setSp(15),
                      fontWeight: FontWeight.w500),
                ),
              ),
            ],
          ),
          Container(
            margin: EdgeInsets.only(top: setWidth(15),bottom: setWidth(30)),
            height: setWidth(0.5),
            color: Color(0xffF0F0F0),
          ),
          Container(

              child: StaggeredGridView.countBuilder(
                physics: NeverScrollableScrollPhysics(),
                shrinkWrap: true,
                crossAxisCount: 4,
                mainAxisSpacing: setWidth(30),
                crossAxisSpacing: setWidth(10),
                staggeredTileBuilder: (i) {
                  return StaggeredTile.fit(1);
                },
                itemCount: isShow?widget.numList.length:4,
                itemBuilder: (context, index) {
                  return GestureDetector(
                    behavior: HitTestBehavior.opaque,
                      onTap: () {
                        urlPush(context, "yuntu://order_page?title=${widget.titleList[index]}&type=$index");
                      },
                      child: _gridItem(
                          widget.numList[index], widget.titleList[index]));
                },
              )),
          GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: (){
              setState(() {
                isShow = !isShow;
              });
            },
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Container(
                  child: Text(
                    isShow? "收起":"展开",
                    style: TextStyle(
                        color: Color(0xff989898),
                        fontSize: setSp(15),
                        fontWeight: FontWeight.w500),
                  ),
                ),
                SizedBox(
                  width: setWidth(5),
                ),
                SizedBox(width: setWidth(15),
                  height: setWidth(10),
                  child: Image.asset(isShow?"assets/images/home_up.png":"assets/images/home_done.png",width: setWidth(15),
                    height: setWidth(10),fit: BoxFit.cover,),
                ),
              ],
            ),
          ),

        ],
      ),
    );
  }

  Container _gridItem(String num, String title) {
    return Container(
      child: Column(
        children: [
          Container(
            child: Text(
              num,
              style: TextStyle(
                  color: Color(0xff323232),
                  fontSize: setSp(24),
                  fontWeight: FontWeight.w600),
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
            ),
          ),
          SizedBox(
            height: setWidth(18),
          ),
          Container(
            child: Text(title,
                style: TextStyle(
                    color: Color(0xff666666),
                    fontSize: setSp(14),)),
          )
        ],
      ),
    );
  }
}
